package com.wesley.jpa.repository;

import com.wesley.jpa.dto.CustomerDto;
import com.wesley.jpa.entity.Customer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * CustomerRepository
 *
 * @author WangPanYong
 * @since 2022/03/16 11:16
 */
@Repository
public interface CustomerRepository extends JpaRepositoryImplementation<Customer, Long> {

    Page<Customer> findByCustName(String custName, Pageable pageable) throws Exception;

    /**
     * Class-based Projections (DTOs)
     * 对查询结果进行扩展
     * @return com.wesley.jpa.dto.CustomerDto
     * @author WangPanYong
     * @since 2022/03/16 16:35
     **/
    List<CustomerDto> findByCustName(String name);

    /**
     * Dynamic Projections
     * @return java.util.List<T>
     * @author WangPanYong
     * @since 2022/03/16 16:42
     **/
    <T> List<T> findByCustId(Long id, Class<T> type);
}
